home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Popular Request
/
By Popular Request (Arsenal Computer)(SysOptics Distribution System).ISO
/
amiga4
/
vidprint.lha
/
VidPrint
/
src
/
ppm2prt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-07
|
5KB
|
209 lines
/* ppm2prt
* This program converts a ppm-file to a file that can be fed
* into a Mitsubishi Videoprinter
*
* Source-code and executable are ⌐'93 by
* Stephan Feinen
* Im Steinfeld 1
* 52076 Aachen
* Germany
*
* Please send comments, criticism and suggestions to:
* feinen@pool.informatik.rwth-aachen.de
*
*/
#define VERSION "1.3beta"
#include <stdio.h>
#include <exec/exec.h>
#include <libraries/dos.h>
typedef unsigned char char_type;
typedef struct FileInfoBlock FileInfoBlock;
char_type magic_header[] = {"\100\066"};
APTR Lock(),Open(),AllocMem(),FreeMem();
ULONG Examine();
UBYTE para,col[3],pos;
char width[5],height[5],dummy,dum[4];
char *aktuell,*adr;
FILE *source,*dest;
int j,z,i;
ULONG laenge,length;
APTR MyLock;
FileInfoBlock MyInfo;
int nomagic = 0;
char version[25]="$VER: 1.4 (05.12.93)";
char vers[10]=VERSION;
Usage()
{
fprintf(stderr,"Usage: ppm2prt POSITION/N FILE/A\n");
fprintf(stderr,"position: 1=top left\n");
fprintf(stderr," 2=top right\n");
fprintf(stderr," 3=bottom left\n");
fprintf(stderr," 4=bottom right\n");
}
main( argc, argv )
int argc; char **argv;
{
fprintf(stderr,"ppm2prt %s ⌐1993 Stephan Feinen\n",vers);
fprintf(stderr,"transmits a PPM to a Mitsubishi Videoprinter\n");
if (argc != 3)
{
Usage();
exit(1);
}
pos=atoi(argv[1]);
if (!(dest = fopen("par:","w"))) exit (puts("Printer not accessible!\n"));
MyLock = Lock(argv[2],ACCESS_READ);
if(!MyLock) exit(puts("Bad Name"));
if(!Examine(MyLock,&MyInfo)) exit(puts("File Not Found"));
laenge = MyInfo.fib_Size;
UnLock(MyLock);
printf("DateilΣnge=%d\n",laenge);
adr = AllocMem(laenge,MEMF_CLEAR);
if(!adr) exit(puts("Out of Memory"));
if(!(source = fopen(argv[2],"r"))) exit(printf("can't open %s\n",argv[2]));
/* Check the magic number */
fscanf(source,"%s",dum);
if(strcmp("P6",dum))
{
fclose(source);
FreeMem(adr,laenge);
exit(fprintf(stderr, "%s: not a ppm-file\n",argv[2]));
}
fscanf(source,"%s",width);
fscanf(source,"%s",height);
fscanf(source,"%s",dum);
fclose(source);
if(!(source = Open(argv[2],MODE_OLDFILE)))
{
FreeMem(adr,laenge);
exit(printf("%s not found\n",argv[2]));
}
Read(source,adr,laenge);
Close(source);
printf("Breite=%s ",width);
printf("H÷he=%s\n",height);
col[0]=82;
col[1]=71;
col[2]=66;
length=atoi(width)*atoi(height);
printf("%d Pixels\n",length);
switch(pos)
{
case 1:
for(j = 0; j < 3; j++)
{
fputc(27,dest);
fputc(87,dest);
fputc(col[j],dest);
fputc(0,dest);
fputc(0,dest);
fputc(0,dest);
fputc(0,dest);
para=(atoi(width)-1) >> 8;
fputc(para,dest);
para=(atoi(width)-1) & 255;
fputc(para,dest);
para=(atoi(height)-1) >> 8;
fputc(para,dest);
para=(atoi(height)-1) & 255;
fputc(para,dest);
for(z = 0; z < length*3 ; z=z+3)
{
aktuell=adr+j+z+15;
fputc(*aktuell,dest);
}
}
break;
case 2:
for(j = 0; j < 3; j++)
{
fputc(27,dest);
fputc(87,dest);
fputc(col[j],dest);
para=(640-atoi(width)) >> 8;
fputc(para,dest);
para=(640-atoi(width)) & 255;
fputc(para,dest);
fputc(0,dest);
fputc(0,dest);
fputc(2,dest);
fputc(127,dest);
para=(atoi(height)-1) >> 8;
fputc(para,dest);
para=(atoi(height)-1) & 255;
fputc(para,dest);
for(z = 0; z < length*3 ; z=z+3)
{
aktuell=adr+j+z+15;
fputc(*aktuell,dest);
}
}
break;
case 3:
for(j = 0; j < 3; j++)
{
fputc(27,dest);
fputc(87,dest);
fputc(col[j],dest);
fputc(0,dest);
fputc(0,dest);
para=(580-atoi(height)) >> 8;
fputc(para,dest);
para=(580-atoi(height)) & 255;
fputc(para,dest);
para=(atoi(width)-1) >> 8;
fputc(para,dest);
para=(atoi(width)-1) & 255;
fputc(para,dest);
fputc(2,dest);
fputc(67,dest);
for(z = 0; z < length*3 ; z=z+3)
{
aktuell=adr+j+z+15;
fputc(*aktuell,dest);
}
}
break;
case 4:
for(j = 0; j < 3; j++)
{
fputc(27,dest);
fputc(87,dest);
fputc(col[j],dest);
para=(640-atoi(width)) >> 8;
fputc(para,dest);
para=(640-atoi(width)) & 255;
fputc(para,dest);
para=(580-atoi(height)) >> 8;
fputc(para,dest);
para=(580-atoi(height)) & 255;
fputc(para,dest);
fputc(2,dest);
fputc(127,dest);
fputc(2,dest);
fputc(67,dest);
for(z = 0; z < length*3 ; z=z+3)
{
aktuell=adr+j+z+15;
fputc(*aktuell,dest);
}
}
break;
default:
FreeMem(adr,laenge);
exit(puts("bad pos-number!"));
}
printf("%d bytes transfered\n",laenge);
fclose(dest);
FreeMem(adr,laenge);
}